#ifndef KHEAP_H
#define KHEAP_H

#include <utils/sorted_array.h>

#define KHEAP_START         0xC0000000
#define KHEAP_INITIAL_SIZE  0x100000
#define HEAP_INDEX_SIZE   0x20000
#define HEAP_MAGIC        0x1234567E
#define HEAP_MIN_SIZE     0x70000

struct kheap_header {
    uint32 magic;
    uint8 is_hole;
    uint32 size;
};

struct kheap_footer {
    uint32 magic;
    struct kheap_header *header;
};

struct kheap {
    struct sorted_array index;
    uint32 start;
    uint32 end;
    uint32 max;
    uint8 flags; // supervisor and readonly
};

struct kheap* kheap_create(uint32 start, uint32 end, uint32 max, uint8 flags);

void* kheap_alloc(struct kheap* heap, uint32 size, uint8 page_align);

void kheap_free(struct kheap* heap, void* p);
#endif
